<template>
	<view class="flex-col page">
		<view class="p-3">
			<view class="d-flex align-items-center pb-1">
				<image class="warning" src="../../static/imgs/warning.png" mode=""></image>
				<text class="font-14 font-600 text-black ps-1">注意事项</text>
			</view>
			<view class="font-14 text-black">
				<view>1. 在下单{{rent_cancel}}分钟内无责取消，扣费将原路返回，超过{{rent_cancel}}分钟将扣除信用分 <text class="ps-2"
						style="text-decoration: underline;"
						@click="$u.route({url:'pages/myReservation/ruleDescription'})">退订规则说明</text></view>
				<view>2. 在租用教室开始时间{{unlock_inadvance_min}}分钟前，密码正式生效</view>
				<view v-if="tip">3. {{tip}}</view>
			</view>
		</view>
		<view class="flex-col group" v-if="myReserveList.length">
			<view class="section_1" v-for="item in myReserveList" :key="item.id">
				<view class="flex-row" style="justify-content: space-between;">
					<view class="flex-row">
						<u-image width="144" height="144" :src="item.room_bannerimage" border-radius="8"></u-image>
						<view class="flex-col group_1">
							<text class="text_3">{{ item.store.store_name | substring(12) }}</text>
							<text class="text_4">{{ item.room.room_name | substring(8)}}</text>
							<text
								class="text_5">{{ item.starttime|setTime('YYYY/MM/DD HH:mm')}}-{{item.endtime|setTime('HH:mm')}}</text>
						</view>
					</view>
					<view class="unlock_button" @click="itemClick(item)">
						开锁
					</view>
				</view>
				<view class="">
					<view class="flex-row justify-between" style="margin-top: 32rpx;">
						<button v-if="rent_refund > 0" class="equal-division-item_1 justify-center"
							hover-class="hoverClass" @click="cancel(item.id)">
							<image src="../../static/svgicon/cancel.svg" class="image_4" />
							<text class="text_9">取消预约</text>
						</button>
						<button class="equal-division-item_1 justify-center" hover-class="hoverClass"
							open-type="contact" @click="">
							<image src="../../static/svgicon/weixin.svg" class="image_4" />
							<text class="text_9">联系客服</text>
						</button>
						<button class="equal-division-item_1 justify-center" hover-class="hoverClass"
							@click="openLocation(item.store.store_latitude, item.store.store_longitude, item.store.store_address)">
							<image src="../../static/svgicon/navigation.svg" class="image_6" />
							<text class="text_9">门店导航</text>
						</button>
					</view>
				</view>
			</view>
		</view>
		<view class="flex-col group" v-else>
			<view class="flex-col group_empey">
				<view class="flex-col items-center group_2">
					<image src="../../static/svgicon/no_record.svg" class="img" />
				</view>
				<text class="text_1">暂无预订信息</text>
			</view>
			<!-- <view class="flex-col items-center button"><text>去预订</text></view> -->
			<button class="button" hover-class="hoverClass" @click="toIndexPage">
				<text class="text_9">去预订</text>
			</button>
		</view>
		<view class="" style="position: fixed; top:880rpx; right: 24rpx;" @click="makePhoneCall('18581555163')">
			<image src="../../static/images/phonecall.png" style="width: 80rpx; height: 150rpx;"></image>
		</view>
	</view>
</template>

<script>
	import moment from 'moment';
	export default {
		data() {
			return {
				myReserveList: [],
				rent_refund: 0,

				unlock_inadvance_min: 0,
				state: '',
				deviceId: '',
				list: [],
				shareContent: {},
				show: false,
				rent_cancel: 0,
				content: '距离开锁时间还有',
				tip: ''
			};
		},
		onLoad() {
			this.loadAndRefresh()

		},
		onPullDownRefresh() {
			this.loadAndRefresh()
			setTimeout(uni.stopPullDownRefresh, 1500)
		},
		onShow() {
			this.loadAndRefresh()
		},
		methods: {
			cancel(id) {
				this.$u.route({
					url: 'pages/myReservation/cancleReservation',
					params: {
						id
					}
				})
			},
			loadAndRefresh() {
				this.$u.api.getMyReserveList().then((res) => {
					this.myReserveList = res.data.reserves
					this.rent_refund = res.data.rent_refund
					this.rent_cancel = res.data.rent_cancel
					this.tip = res.data.tip
					this.unlock_inadvance_min = res.data.unlock_inadvance_min
				}).catch((e) => {
					this.list = []
				})
			},
			itemClick({
				starttime,
				room,
				id,
				endtime
			}) {
				if (Date.now() < moment(starttime).subtract(this.unlock_inadvance_min, 'minutes').valueOf()) {
					uni.showModal({
						title: '提示',
						content: `密码在开始时间前${this.unlock_inadvance_min}分后提供，不影响前面的用户`,
						showCancel: false,
					});
				} else {
					this.$u.route({
						url: 'pages/myReservation/automaticUnlocking',
						params: {
							id: id
						}
					});
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.page {
		.unlock_button {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			background: linear-gradient(135deg, #E85389 15.23%, #E25588 84.77%);
			color: white;
			font-style: normal;
			font-weight: 500;
			font-size: 14px;
			line-height: 100rpx;
			text-align: center;
			margin-top: 26rpx;
			margin-right: 20rpx;
		}

		background-color: #ffffff;
		width: 100%;
		overflow-y: auto;
		height: 100%;

		.group_empey {
			color: rgb(51, 51, 51);
			font-size: 28rpx;
			font-weight: 200;
			line-height: 40rpx;
			white-space: nowrap;
			padding-top: 146rpx;

			.group_2 {
				position: relative;
				align-items: center;

				.img {
					width: 150rpx;
					height: 188rpx;
				}
			}

			.text_1 {
				margin-top: 54rpx;
				align-self: center;
			}
		}

		.button {
			margin-top: 52rpx;
			padding: 14rpx 0 16rpx;
			align-self: center;
			color: rgb(255, 255, 255);
			font-size: 36rpx;
			font-weight: 600;
			line-height: 50rpx;
			white-space: nowrap;
			background-color: rgb(216, 88, 134);
			border-radius: 8rpx;
			width: 300rpx;
		}

		.group {
			padding: 0rpx 22rpx 20rpx 24rpx;
			flex: 1 1 auto;
			overflow-y: auto;

			.button {
				border-radius: 8rpx;
				border: solid 4rpx rgb(216, 88, 134);
				color: #FFFFFF;
				background-color: rgb(216, 88, 134);
				font-size: 28rpx;
				font-weight: 600;
				line-height: 40rpx;
				align-items: center;
			}

			.hoverClass {
				background-color: rgba(216, 88, 134, 0.2);
				color: rgb(216, 88, 134);
				border: solid 4rpx rgb(216, 88, 134);
			}

			.section_1 {
				padding: 30rpx 22rpx;
				background-color: rgb(255, 255, 255);
				box-shadow: 0px 4rpx 8rpx 0px rgb(238, 235, 236);
				border-radius: 16rpx;
				border: solid 2rpx rgb(236, 236, 236);
				margin-top: 30rpx;

				.group_1 {
					margin-left: 32rpx;
					flex: 1 1 auto;

					.text_3 {
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 600;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_4 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 200;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_5 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 200;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.group_2 {
						margin-top: 12rpx;
						color: rgb(51, 51, 51);
						font-size: 28rpx;
						font-weight: 600;
						line-height: 40rpx;
						white-space: nowrap;

						.text_7 {
							margin-left: 12rpx;
						}

						.image_3 {
							margin: 0rpx 0 0rpx 24rpx;
							width: 40rpx;
							height: 36rpx;
						}
					}

					.equal-division {
						margin-top: 32rpx;

						.equal-division-item {
							border: none;
							padding: 4rpx 15rpx 6rpx;
							flex: 1 1 208rpx;
							border-radius: 8rpx;
							border: solid 4rpx rgb(216, 88, 134);
							color: rgb(216, 88, 134);
							font-size: 28rpx;
							font-weight: 600;
							line-height: 40rpx;
							background-color: #FFFFFF;
							align-items: center;

							.text_8 {
								margin-left: 15rpx;
							}
						}

						.hoverClass {
							background-color: rgba(216, 88, 134, 0.2);
							color: rgb(216, 88, 134);
							border: solid 4rpx rgb(216, 88, 134);
						}
					}
				}
			}

			.left-section {
				height: 240rpx;
				overflow: hidden;
				// border: solid 4rpx rgb(216, 88, 134);
				border-radius: 16px;

				.text_1 {
					margin-top: 12rpx;

				}
			}

			.section_use {
				border: solid 4rpx rgb(236, 236, 236);
				color: rgba(213, 213, 213, 1);
			}

			.equal-division-item_1 {
				width: 208rpx;
				color: rgb(216, 88, 134);
				font-size: 28rpx;
				font-weight: 600;
				line-height: 40rpx;
				padding: 4rpx 14rpx 6rpx;
				border-radius: 8rpx;
				height: 62rpx;
				border: solid 4rpx rgb(216, 88, 134);
				background-color: #FFFFFF;
				align-items: center;

				.image_6 {
					width: 40rpx;
					height: 38rpx;
				}

				.text_9 {
					margin-left: 16rpx;
				}
			}

			.hoverClass {
				background-color: rgba(216, 88, 134, 0.2);
				color: rgb(216, 88, 134);
				border: solid 4rpx rgb(216, 88, 134);
			}

			.image_1 {
				width: 180rpx;
				height: 194rpx;
				border-radius: 16rpx;
			}

			.image_4 {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.note {
			margin-top: 24rpx;
			font-size: 24rpx;
			color: #333333;
		}

		.warning {
			width: 36rpx;
			height: 36rpx;
			margin-top: 4rpx;
			// vertical-align: middle;
		}
	}
</style>